package com.cskaoyan.config;

import com.cskaoyan.filter.CustomFilter;
import com.cskaoyan.interceptor.HandlerInterceptor1;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Arrays;
import java.util.List;

/**
 * @author stone
 * @date 2022/08/11 14:28
 */
//@EnableWebMvc // 增加该注解，会让该配置类生效
@Configuration  // 对SpringBoot做的配置项的补充
public class MvcConfiguration implements WebMvcConfigurer {
    /*@Bean
    public FilterRegistrationBean filterRegistrationBean() {
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
        filterRegistrationBean.setFilter(new CustomFilter());
        List<String> urlPatterns = Arrays.asList("/*");
        filterRegistrationBean.setUrlPatterns(urlPatterns);
        return filterRegistrationBean;
    }*/

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new HandlerInterceptor1());// 默认作用范围/**
    }

    /*@Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("来源于参数类").addResourceLocations("来源于参数类");
    }*/
}
